<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <title>客户表单</title>
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css"/>
    <style>
        .layui-form{width: 80%;margin: 0 auto;}
        .layui-input-block{width: 60%;}
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="example" id="editForm">
    <div class="layui-row" style="margin-top: 20px;">
        <div class="layui-col-md6" >
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" lay-verify="username" autocomplete="off" placeholder="请输入姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地区</label>
                <div class="layui-inline" style="width: 260px;">
                    <select name="province" id="province" lay-verify="required" lay-search lay-filter="province">
                        <option value="">省份</option>
                    </select>
                </div>
                <div class="layui-inline" style="margin-left: 110px;width: 260px">
                    <select name="city" id="city" lay-verify="required" lay-search lay-filter="city">
                        <option value="">地级市</option>
                    </select>
                </div>
                <div class="layui-inline" style="margin-left: 110px;width: 260px">
                    <select name="district" id="district" lay-verify="required" lay-search>
                        <option value="">县/区</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">经理</label>
                <div class="layui-input-block">
                    <input type="text" id="cusManager" lay-verify="required" name="cusManager" placeholder="请输入经理名字" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">级别</label>
                <div class="layui-input-block">
                    <select name="level" lay-filter="level" lay-verify="required">
                        <option value=""></option>
                        <option value="1" selected="">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">满意度</label>
                <div class="layui-input-block">
                    <select name="satisfaction" lay-filter="satisfaction" lay-verify="required">
                        <option value=""></option>
                        <option value="1" selected="">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">信用度</label>
                <div class="layui-input-block">
                    <select name="creditLine" lay-filter="creditLine" lay-verify="required">
                        <option value=""></option>
                        <option value="1" selected="">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-block">
                    <input type="text" id="address" lay-verify="required" name="address" placeholder="请输入公司地址" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">邮编</label>
                <div class="layui-input-block">
                    <input type="text" id="postCode" name="postCode" placeholder="请输入邮编" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-block">
                    <input type="text" id="tel" name="tel" lay-verify="tel" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">公司网址</label>
                <div class="layui-input-block">
                    <input type="text" id="webSite" name="webSite" placeholder="请输入公司网址" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">注册资金</label>
                <div class="layui-input-block">
                    <input type="text" id="regCaptial" name="regCaptial" placeholder="请输入注册资金" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开户银行</label>
                <div class="layui-input-block">
                    <input type="text" id="depBank" name="depBank" placeholder="请输入开户银行" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开户账号</label>
                <div class="layui-input-block">
                    <input type="text" id="depAccount" name="depAccount" placeholder="请输入开户账号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年营业额</label>
                <div class="layui-input-block">
                    <input type="text" id="yearlyTurnover" name="yearlyTurnover" placeholder="请输入年营业额" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">流失状态</label>
                <div class="layui-input-block" style="width: 30%;">
                    <input type="radio" name="state" value="1" title="是">
                    <input type="radio" name="state" value="0" title="否" checked="">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="width: 100%;margin-top: 30px;">
        <div class="layui-input-block" style="width: 80%;margin: 0 auto;text-align: center;">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="putIn">提交</button>
<!--            <button type="submit" class="layui-btn" lay-submit="" lay-filter="update">保存修改</button>-->
        </div>
        <!--        把id输入框设为隐藏-->
        <div class="layui-form-item" hidden>
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="hidden" id="id" name="id" lay-verify="title" autocomplete="off" placeholder="请输入姓名" class="layui-input">
            </div>
        </div>
    </div>
</form>

<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="../../js/jquery3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/area.js" type="text/javascript"></script>
<script src="../../js/select.js" type="text/javascript"></script>
<script>
    layui.use(['form'], function(){
        var form = layui.form;
        //判断是新增还是修改
        var myUrl="";
        if ($('#id').val() == ""){
            myUrl="http://localhost:8080/crm/customer/save";
        }else{
            myUrl="http://localhost:8080/crm/customer/update";
        }
        //监听添加
        form.on('submit(putIn)', function(data){
            layer.alert("恭喜你，添加成功！",{
                title: 'crm提示'
            })
            //向后台发送ajax请求
            $.ajax({
                //编写json格式，设置属性和值
                url:myUrl,
                contentType:"application/json;charset=utf-8",
                data:JSON.stringify(data.field),
                dataType:"json",
                type:"post",
                async:false,
                success:function (data){
                },
                end:parent.location.reload()
            })
            return false;
        });
        //表单验证
        form.verify({
            username: function(value, item) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '姓名不能为空且不能含有特殊字符';
                }
            }
            ,tel:function (value) {
                if (!new RegExp("^[1][0-9]{10}$").test(value)){
                    return '手机号只能是11位数字';
                }
            }
        })
    });
    //地址
    function jg(){
        alert($("#province").val()+$("#city").val()+$("#district").val());
    }

</script>
</body>
</html>